package com.ad.common.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;

import com.ad.common.entity.UserInfo;

/**
 	* A data access object (DAO) providing persistence and search support for UserInfo entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see .UserInfo
  * @author MyEclipse Persistence Tools 
 */

public class UserInfoDAO extends BaseDAO  {
    private static final Log log = LogFactory.getLog(UserInfoDAO.class);
	//property constants
	public static final String USER_ICON = "userIcon";
	public static final String USER_REALNAME = "userRealname";
	public static final String COMPANY = "company";
	public static final String MOBILE = "mobile";
	public static final String EMAIL = "email";
	public static final String WEB_SITE = "webSite";
	public static final String COMPANY_ADDR = "companyAddr";
	public static final String PHONE = "phone";
	public static final String FAX = "fax";
	public static final String QQ = "qq";
	public static final String ALIPAY = "alipay";
	public static final String BANK_NAME = "bankName";
	public static final String BANK_CARD_NUMBER = "bankCardNumber";
	public static final String SEX = "sex";



    
    public void save(UserInfo transientInstance) {
        log.debug("saving UserInfo instance");
        try {
        	this.getHibernateTemplate().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(UserInfo persistentInstance) {
        log.debug("deleting UserInfo instance");
        try {
        	this.getHibernateTemplate().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public UserInfo findById( java.lang.Integer id) {
        log.debug("getting UserInfo instance with id: " + id);
        try {
            UserInfo instance = (UserInfo)this.getHibernateTemplate().get("UserInfo", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(UserInfo instance) {
        log.debug("finding UserInfo instance by example");
        try {
            List results = this.getHibernateTemplate().findByExample(instance);
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding UserInfo instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from UserInfo as model where model." 
         						+ propertyName + "= ?";
         return getHibernateTemplate().find(queryString, value);
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByUserIcon(Object userIcon
	) {
		return findByProperty(USER_ICON, userIcon
		);
	}
	
	public List findByUserRealname(Object userRealname
	) {
		return findByProperty(USER_REALNAME, userRealname
		);
	}
	
	public List findByCompany(Object company
	) {
		return findByProperty(COMPANY, company
		);
	}
	
	public List findByMobile(Object mobile
	) {
		return findByProperty(MOBILE, mobile
		);
	}
	
	public List findByEmail(Object email
	) {
		return findByProperty(EMAIL, email
		);
	}
	
	public List findByWebSite(Object webSite
	) {
		return findByProperty(WEB_SITE, webSite
		);
	}
	
	public List findByCompanyAddr(Object companyAddr
	) {
		return findByProperty(COMPANY_ADDR, companyAddr
		);
	}
	
	public List findByPhone(Object phone
	) {
		return findByProperty(PHONE, phone
		);
	}
	
	public List findByFax(Object fax
	) {
		return findByProperty(FAX, fax
		);
	}
	
	public List findByQq(Object qq
	) {
		return findByProperty(QQ, qq
		);
	}
	
	public List findByAlipay(Object alipay
	) {
		return findByProperty(ALIPAY, alipay
		);
	}
	
	public List findByBankName(Object bankName
	) {
		return findByProperty(BANK_NAME, bankName
		);
	}
	
	public List findByBankCardNumber(Object bankCardNumber
	) {
		return findByProperty(BANK_CARD_NUMBER, bankCardNumber
		);
	}
	
	public List findBySex(Object sex
	) {
		return findByProperty(SEX, sex
		);
	}
	

	public List findAll() {
		log.debug("finding all UserInfo instances");
		try {
			String queryString = "from UserInfo";
	         return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public UserInfo merge(UserInfo detachedInstance) {
        log.debug("merging UserInfo instance");
        try {
            UserInfo result = (UserInfo) getHibernateTemplate().merge(
					detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(UserInfo instance) {
        log.debug("attaching dirty UserInfo instance");
        try {
        	getHibernateTemplate().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(UserInfo instance) {
        log.debug("attaching clean UserInfo instance");
        try {
        	getHibernateTemplate().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}